//
//  SwiftMessageManager.swift
//  TestWorkSpace
//
//  Created by Mac on 2020/1/3.
//  Copyright © 2020 jhf. All rights reserved.
//

import UIKit
import SwiftMessages

struct MessageManager {
    /// 生产 status 的抽取方法
    /// - Parameters:
    ///   - layoutType: 布局样式
    ///   - themeType: 消息类型
    ///   - iconImageType: 消息图标的类型
    ///   - presentationStyleType: 模态的位置
    ///   - title: 标题
    ///   - body: 说明文字
    ///   - isHiddenBtn: 是否 隐藏 按钮
    ///   - seconds: 显示的时间
    @MainActor static func showMessage(layoutType: MessageView.Layout = .cardView, themeType: Theme = .info , iconImageType: IconStyle = .default, presentationStyleType: SwiftMessages.PresentationStyle = .top, title: String = "温馨提示", body: String, isHiddenBtn: Bool = true, seconds: SwiftMessages.Duration = .automatic ) {
        
        let view = MessageView.viewFromNib(layout: layoutType)
        view.configureContent(title: title, body: body, iconImage: nil, iconText: nil, buttonImage: nil, buttonTitle: "隐藏", buttonTapHandler: { _ in SwiftMessages.hide() })
        view.configureTheme(themeType, iconStyle: iconImageType)
        view.button?.isHidden = isHiddenBtn
        
        var config = SwiftMessages.defaultConfig
        config.prefersStatusBarHidden = false
        config.presentationStyle = presentationStyleType
        config.preferredStatusBarStyle = .none
        config.duration = seconds
        config.shouldAutorotate = true
        config.interactiveHide = true
        print(config)
        
        SwiftMessages.show(config: config, view: view)
            
    }
    
}
